package com.winz.cultureapp.http.request;

import android.text.TextUtils;

import com.winz.cultureapp.entity.request.UserSendReq;
import com.winz.cultureapp.utils.JsonUtil;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * 网络请求参数管理
 */
public class

RequestFactory {
	private static HashMap<String, String> maps = new HashMap<>();
	private static RequestFactory factory = new RequestFactory();
	private static Map<String, RequestBody> map_formData = new HashMap<>();

	public RequestFactory(){
		
	}
	
	public static RequestFactory getInstance() {
		return factory;
    }


	/**
	 * 清空
	 */
	public void clean(){
		maps.clear();
	}

	/**
	 * 登录
	 * @param
	 * @return
	 */
	public String login(String communist_party_no,String communist_name,String communist_password){
		clean();
		maps.put("communist_party_no",communist_party_no);
		maps.put("communist_name",communist_name);
		maps.put("communist_password",communist_password);

		return JsonUtil.getJsonFromObj(maps);
	}



	/**
	 * 上传头像
	 * @return
	 */
	public Map<String, RequestBody> upLoadHeader(String content){
		map_formData.put("communist_no",
				RequestBody.create(MediaType.parse("form-data"), content));
		return map_formData;
	}
	public MultipartBody.Part upLoadHeader_file(String file){
		File pic = new File(file);
		RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"),pic);
		MultipartBody.Part body = MultipartBody.Part.createFormData("file",pic.getName(),requestBody);

		return body;
	}

//	/**
//	 * 新闻公告列表
//	 * @param
//	 * @return
//	 */
//	public String news(String type,String page,String limit){
//		clean();
//		maps.put("type",type);
//		maps.put("page",page);
//		maps.put("limit",limit);
//
//		return JsonUtil.getJsonFromObj(maps);
//	}





//	public String league(String page,String limit){
//		return "?page="+page+"&limit="+limit;
//	}


	/**
	 * 文体社团
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> league(String page,String limit,String categoryId,String areaId,String sort){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("categoryId",categoryId);
		maps.put("areaId",areaId);
		maps.put("sort",sort);
		return maps;
	}

	/**
	 * 我的文体社团
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> league_my(String page,String limit){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		return maps;
	}

	/**
	 * 首页活动
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> activity(String page,String limit,String unitId,String areaId,String categoryId,String sort){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("unitId",unitId);
		maps.put("areaId",areaId);
		maps.put("categoryId",categoryId);
		maps.put("sort",sort);
		return maps;
	}

	/**
	 * 获取文化场馆列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> unit_culture(String page,String limit,String areaId,String categoryId){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("areaId",areaId);
		maps.put("categoryId",categoryId);
		return maps;
	}

	/**
	 * App更新
	 * @param versionCode 版本号
	 * @param appType app类型
	 * @return
	 */
	public Map<String, String> app_update(String versionCode,String appType){
		maps.clear();
		maps.put("versionCode",versionCode);
		maps.put("appType",appType);
		return maps;
	}

	/**
	 * 场馆列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> unit_search(String page,String limit,String areaId,String categoryId,String functionCategoryId){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("areaId",areaId);
		maps.put("categoryId",categoryId);
		maps.put("functionCategoryId",functionCategoryId);
		return maps;
	}

	/**
	 * 根据分类获取该分类下的内容列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> legacy(String page,String limit,String cid){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("cid",cid);
		return maps;
	}

	/**
	 * 获取分类获取内容列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> volunteer(String page,String limit,String cid){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("cid",cid);
		return maps;
	}

	/**
	 * 获取艺术鉴赏内容列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> art(String page,String limit,String categoryId){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("categoryId",categoryId);
		return maps;
	}

	/**
	 * 获取所有文物鉴赏列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> cultural(String page,String limit,String unitId,String categoryId){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("unitId",unitId);
		maps.put("categoryId",categoryId);
		return maps;
	}

	/**
	 * 获取全部志愿活动列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> volunteer_activity(String page,String limit){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		return maps;
	}

	/**
	 * 我的消息列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> user_message(String page,String limit){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		return maps;
	}

	/**
	 * 获取全部志愿活动列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> user_collection(String page,String limit,String type){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("type",type);
		return maps;
	}

	/**
	 * 新闻列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> news(String categoryId,String page,String limit){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("categoryId",categoryId);
		return maps;
	}


	/**
	 * 固定场馆预定记录
	 */
	public Map<String, String> unit_book_fix_record(String page,String limit){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		return maps;
	}


	/**
	 * 管理员验证过的固定场馆预订列表
	 */
	public Map<String, String> admin_user_unit_book_list(String page,String limit){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		return maps;
	}


	/**
	 * 子场馆列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> unit_child(String page,String limit,String parentId,String date,String time){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("parentId",parentId);
		if (!TextUtils.isEmpty(date)){
			maps.put("date",date);
		}
		if (!TextUtils.isEmpty(time)){
			maps.put("time",time);
		}
		return maps;
	}

	/**
	 * 保存非固定场馆预定信息
	 * @return
	 */
	public MultipartBody unit_book_unfix(String name,String phone,String type,String purpose,String unitId,File file){
		MultipartBody.Builder builder = new MultipartBody.Builder();
		//文本部分
		builder.addFormDataPart("name", name);
		builder.addFormDataPart("phone", phone);
		builder.addFormDataPart("type", type);
		builder.addFormDataPart("purpose", purpose);
		builder.addFormDataPart("unitId", unitId);

		//文件部分
		if (file != null && file.exists()){
			RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
			builder.addFormDataPart("file", file.getName(), requestBody); // “file”为文件参数的参数名（由服务器后台提供）
		}
		builder.setType(MultipartBody.FORM);
		MultipartBody multipartBody = builder.build();

		return multipartBody;
	}

	/**
	 * 根据条件筛选场馆预定时间表
	 */
	public Map<String, String> unit_book_schedule(String selectDate,String unitId){
		maps.clear();
		maps.put("selectDate",selectDate);
		maps.put("unitId",unitId);
		return maps;
	}


	/**
	 * 场馆详情
	 * @param id
	 * @return
	 */
	public String unit_detail(String id){

		return id;
	}

	/**
	 * 获取艺术鉴赏子内容列表
	 * @param page
	 * @param limit
	 * @return
	 */
	public Map<String, String> art_child(String page,String limit,String artType,String id){
		maps.clear();
		maps.put("page",page);
		maps.put("limit",limit);
		maps.put("artType",artType);
		maps.put("id",id);
		return maps;
	}

	/**
	 * 实名认证
	 * @return
	 */
	public MultipartBody user_auth(String realname,String phone,String idcard,String cardStartDate,String cardEndDate,File file1,File file2){
		MultipartBody.Builder builder = new MultipartBody.Builder();
		//文本部分
		builder.addFormDataPart("realname", realname);
		builder.addFormDataPart("phone", phone);
		builder.addFormDataPart("idcard", idcard);
		builder.addFormDataPart("cardStartDate", cardStartDate);
		builder.addFormDataPart("cardEndDate", cardEndDate);

		//文件部分
		if (file1 != null && file1.exists()){
			RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file1);
			builder.addFormDataPart("file", file1.getName(), requestBody); // “file”为文件参数的参数名（由服务器后台提供）
		}
		if (file2 != null && file2.exists()){
			RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file2);
			builder.addFormDataPart("file1", file2.getName(), requestBody); // “file”为文件参数的参数名（由服务器后台提供）
		}
		builder.setType(MultipartBody.FORM);
		MultipartBody multipartBody = builder.build();

		return multipartBody;
	}

	/**
	 * 上传头像
	 * @return
	 */
	public MultipartBody user_headerimage(File file){
		MultipartBody.Builder builder = new MultipartBody.Builder();

		//文件部分
		if (file != null && file.exists()){
			RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
			builder.addFormDataPart("file", file.getName(), requestBody); // “file”为文件参数的参数名（由服务器后台提供）
		}

		builder.setType(MultipartBody.FORM);
		MultipartBody multipartBody = builder.build();

		return multipartBody;
	}
}
